<?php

namespace app\admin\controller;

use app\admin\Controller;
use think\Db;

class Article extends Controller
{
    use \app\admin\traits\controller\Controller;

    // 方法黑名单
    protected static $blacklist = [];

    protected function filter(&$map)
    {
        if ($this->request->param("title")) {
            $map['title'] = ["like", "%" . $this->request->param("title") . "%"];
        }
    }
    
    protected function formate_list(&$list)
    {
        $type = $this->getType();
        foreach ($list as $k=>$v) {
            
        }
    }

    protected function beforeIndex()
    {
        //获取全部文章分类，用以筛选
        $type = \Fields::getById('article');
        $this->view->assign('type', $type);
    }

    protected function beforeAdd()
    {
        $this->getType();
    }
    
    protected function beforeEdit()
    {
        $this->getType();
    }
    
    private function getType($return = false)
    {
        $type = \Fields::getById("article");
        $this->view->assign("type", $type);
        return $return ? $type : true;
    }
    
    //分类文章列表
    public function cate_list(){
        $id = $this->request->param('id/d',0);//分类ID
        $title = $this->request->param('title/s','0');//文章名称
        $where = ['status'=>1,'isdelete'=>0];
        if($id){
            $where['type_id'] = $id;
        }
        if($title){
            $where['title'] = ['like','%'.$title.'%'];
        }
        $list = $this->datalist(model('article'),$where);
        return $this->view->fetch();
    }
}
